Imports System.Linq
Imports System.Net
Imports System.Text

Friend Class HttpGetRequest
    Inherits HttpRequest
    Public Sub New(endpointUrl As String)
        MyBase.New(endpointUrl)
    End Sub

    Public Overrides Function IssueRequest() As HttpWebResponse
        ' Build a string with all the params, properly encoded.
        Dim p = New StringBuilder()
        'For Each key As var In paramTable.Keys.Cast(Of String)().Where(Function(key) paramTable(key) IsNot Nothing)
        For Each key As String In paramTable.Keys
            If key IsNot Nothing Then
                p.Append(key)
                p.Append("=")
                p.Append(Uri.EscapeDataString(paramTable(key).ToString()))
                p.Append("&")
            End If
        Next

        Dim req = TryCast(WebRequest.Create(EndpointUrl & "?" & p.ToString), HttpWebRequest)

        Try
            If req IsNot Nothing Then
                Dim response = TryCast(req.GetResponse(), HttpWebResponse)
                Return response
            End If
        Catch ex As Exception
            Console.[Error].WriteLine(ex.Message)
            Return Nothing
        End Try

        Return Nothing
    End Function
End Class
